gdgs.ndp.storage = {
		storage: null,
		getStorage: function(){
			if(!this.storage){
				this.storage = window.sessionStorage || 
							(window.UserDataStorage && new UserDataStorage()) || 
							window.localStorage ||
							(window.cookieStorage && new cookieStorage()) || 
							$map();
				if(this.storage instanceof dorado.util.Map){
					this.storage.setItem = function(key, value){
						this.put(key, value);
					};
					this.storage.getItem = function(key){
						return this.get(key);
					};
					this.storage.removeItem = function(key){
						return this.remove(key);
					};
				}
			}
			return this.storage;
		},
		setItem: function(key, value){
			this.getStorage().setItem(key, value);
		},
		getItem: function(key){
			return this.getStorage().getItem(key);
		},
		removeItem: function(key){
			this.getStorage().removeItem(key);
		},
		getName: function(index){
			return this.getStorage().key(index);
		},
		getItemByIndex: function(index){
			return this.getStorage().getItem(this.getName(index));
		},
		size: function(){
			return this.getStorage().length;
		},
		each: function(fn){
			var size = this.size();
			for (var i = 0; i < size; i++) {
				var name = this.getName(i);
				if (fn.call(name, this.getItem(name), i) === false) {
					return i;
				}
			}
		},
		clear: function(){
			this.getStorage().clear();
		}
};

gdgs.ndp.storage.getMappingValues = function(storageKey, view, self){
	var datas = gdgs.ndp.storage.getItem(storageKey);
	if('null'== datas ||!datas){
		if(!view){
			view = window;
		}
		if(!self){
			self = view;
		}
		var action = self.$_LoadPropertyDefMappingAjaxAction;
		if (!action) {
			action = new dorado.widget.AjaxAction({
				async: false,
				service : "gdgs.base.dataMapInterceptor#getMapping"
			});
			self.$_LoadPropertyDefMappingAjaxAction = action;
		}
		action.set("parameter", {
			sqlKey : storageKey
		});
		action.execute(function(data){
			datas = data;
			gdgs.ndp.storage.setItem(storageKey, dorado.JSON.stringify(data));
		});
	}else{
		datas = dorado.JSON.parse(datas);
	}
	return datas;
};
gdgs.ndp.storage.getJoinMappingValues = function(storageKey, paras, view, self){
	var sKey = storageKey + "__" + paras.key;
	var datas = gdgs.ndp.storage.getItem(sKey);
	if(!datas){
		if(!view){
			view = window;
		}
		if(!self){
			self = view;
		}
		var action = self.$_LoadPropertyDefJoinMappingAjaxAction;
		if (!action) {
			action = new dorado.widget.AjaxAction({
				async: false,
				service : "gdgs.base.dataMapInterceptor#getJoinMapping"
			});
			self.$_LoadPropertyDefJoinMappingAjaxAction = action;
		}
		action.set("parameter", {
			sqlKey : storageKey,
			paras: paras
		});
		action.execute(function(data){
			datas = data;
			gdgs.ndp.storage.setItem(sKey, dorado.JSON.stringify(data));
		});
	}else{
		datas = dorado.JSON.parse(datas);
	}
	return datas;
};


dorado.BasePropertyDef.prototype.ATTRIBUTES.userData.setter = function(userData) {
	this._userData = userData;
	if(!this._mapping && userData && userData.$_mappingStorageKey){
		this.set("mapping", gdgs.ndp.storage.getMappingValues(userData.$_mappingStorageKey, this.get("view"), this));
	}
};